package java_class_work.week08.internet.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @Author Tiam
 * @Date 2022/11/1 10:25
 * @Description: 客户端-发送数据
 */
public class TcpClient01 {
    public static void main(String[] args) {
        try {
            // 1. 创建Socket, 指定端口和IP
            Socket socket = new Socket("127.0.0.1", 6666);
            // 2. 准备数据, 获取流资源
            byte[] bytes = "test".getBytes();
            OutputStream outputStream = socket.getOutputStream();
            // 3. 通过输入输出流进行数据交互
            outputStream.write(bytes);
            // 4. 关闭流资源和Socket
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
